<!---
Name:        login.cfm
Author:      Dmitry Svito (prostotelo@gmail.com)
Description: admin login
Created:     26.03.2011
--->

<cfparam name="Form.Operation" type="string" default="0">
<cfparam name="Form.remuser" type="string" default="No">
<cfparam name="Form.userlogin" type="string" default="">
<cfparam name="Form.userpassword" type="string" default="">
<cfparam name="userlogin" type="string" default="0">
<cfparam name="userpassword" type="string" default="0">
<cfparam name="admintag" type="boolean" default="false">
<cfparam name="remuser" type="string" default="No">

<cfset UserObjGate = createObject("component", "Catalog.DataAccessLayer.UsersGateway").init()>

<cfif IsDefined("Cookie.UrLog")>
	<cfset remuser = #Cookie.UrLog#>
	<cfif remuser IS "Yes">
		<cfif IsDefined("Cookie.ULogin")>
			<cfset userlogin = #Cookie.ULogin#>
		</cfif>
		<cfif IsDefined("Cookie.UPass")>
			<cfset userpassword = #Cookie.UPass#>
		</cfif>	
	</cfif>
</cfif>

<cfcookie name="UrLog" value="#Form.remuser#" expires="1">
<cfcookie name="ULogin" value="#Form.userlogin#" expires="1">
<cfcookie name="UPass" value="#Form.userpassword#" expires="1">		

<html>
<head>
	<title>
		Joe's Catalog
		Login
	</title>
</head>
<body>
<cfform name="loginform" action="login.cfm" method="post" accept-charset="utf-8">
<table width="20%" border="0" cellspacing="2" cellpadding="2" summary="table">
    <caption align="top">
        <strong>Login</strong>
    </caption>
    <tr>
        <td align="right">
        	Username:
        </td>
        <td>
        	<cfinput type="text" name="userlogin" value="#userlogin#"
			maxlength="10"
            required="yes"
            message="Username is required!"
            validateAt="onSubmit">			
		</td>
    </tr>
    <tr>
        <td align="right">
        	Password:
        </td>
        <td>
        	<cfinput type="password" name="userpassword" value="#userpassword#"
			maxlength="10"
            required="yes"
            message="Password is required!"
            validateAt="onSubmit">			
        </td>
    </tr>
    <tr>
        <td align="right">
        	Remember?
        </td>
        <td>
        	<input type="checkbox" name="remuser" value="Yes" <cfif remuser IS "Yes"> checked </cfif> >
        </td>
    </tr>
    <tr>
        <td colspan="2" align="center">
        	<cfinput type="submit" name="Operation" value="Login" />
        </td>
    </tr>	
</table>
</cfform>
</body>
</html>
<cfif Form.Operation IS "Login">
	<cfset admintag = UserObjGate.CheckUserData(userlogin, userpassword)>

	<cfif #admintag#>
		<cfset session.Logged = "true">
		<cfset session.User = "#userlogin#">
		<cflocation url="/catalog/businesslayer/secure/categories.cfm">
	<cfelse>
		<cfoutput>
			Login or password is incorrect.
		</cfoutput>	
	</cfif>
</cfif>
